package com.shouhuobao.take.invite;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shouhuobao.station.R;
import com.shouhuobao.take.model.StationInviteHistoryBean;
import com.shouhuobao.take.utils.StringUtils;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;

/**
 * Created by joker on 2017/9/26.
 * 邀请好友开通记录适配器
 */
public class StationInviteHistoryAdapter extends BaseAdapterExt<StationInviteHistoryBean> {

    public StationInviteHistoryAdapter(ArrayList<StationInviteHistoryBean> items, Activity context) {
        super(items, context);
        setEmptyView(R.layout.station_invite_empty);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_station_invate_history, parent, false);
            holder.phoneTV = (TextView) convertView.findViewById(R.id.station_phone_tv);
            holder.levelTV = (TextView) convertView.findViewById(R.id.station_level_tv);
            holder.openStatusTV = (TextView) convertView.findViewById(R.id.station_status_tv);
            holder.awardMoneyTV = (TextView) convertView.findViewById(R.id.station_money_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final StationInviteHistoryBean item = items.get(position);
        holder.phoneTV.setText(item.getInvitedPhone());
        if (!StringUtils.isEmpty(item.getStationLevel())) {
            holder.levelTV.setText(item.getStationLevel());
        }
        //驿站已开通
        if ("1".equals(item.getStationStatus())) {
            holder.openStatusTV.setText("已开通");
            if (!StringUtils.isEmpty(item.getReward())) {
                holder.awardMoneyTV.setText(item.getReward() + "元");
            }
        } else {
            holder.openStatusTV.setText("未开通");
        }
        return convertView;
    }

    private class ViewHolder {
        TextView phoneTV;//驿站手机号
        TextView levelTV;//驿站级别
        TextView openStatusTV;//驿站开通状态
        TextView awardMoneyTV;//奖励金
    }
}
